Repository navigation
Combat 4.3a: Add DivinityHitEvent and honour the outer request for DIVINITY_ types - #389
Merged
Merged
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FaEyTuWrM4QJyDXghv2vfE
…VINITY_ types DivinityHitEvent.Prepare fires after Codex scaling and before Start, with the damage and defense per type open to change. DivinityHitEvent.Result fires after the per-type formula and before anything is written to the Bukkit event, with Divinity's final numbers per type open to change. Both report the claimed Codex request, the hit's origin (inferred without a request), how Divinity handled the weapon, and the typed amounts. The old DivinityDamageEvent subclasses are deprecated and keep firing at the same points. DamageManager.dealDamage used to open its own REPLACE request even when a dealer's request was already open on the target, so the dealer's weapon-stats mode and origin were lost, and its request stayed open for the next hit to claim. It now records the typed amount locally and lets the listener claim the dealer's request: RAW leaves the hit alone, IGNORE uses only the typed amount and is exempt, anything else replaces as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FaEyTuWrM4QJyDXghv2vfE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Design
Phase 4.3a of the combat restructure (#365). Divinity only. Fabled's side (4.3b) comes later and is not part of this PR.
Events
There is a new class,
studio.magemonkey.divinity.api.event.DivinityHitEvent, with two concrete events. Each one has its ownHandlerListand extends Bukkit'sEventdirectly, not Codex'sIEvent.IEventhas oneHandlerListshared by every Codex event. Listen toPrepareorResult, not to the abstract base.Both events expose the same read-only hit description:
getVictim(),getAttacker()(nullable),getProjectile()(nullable),getWeapon(),getCause(),getOriginalEvent()getRequest()(nullable)DamageRequestthis hit claimed. For aDIVINITY_<type>hit dealt inside a dealer's open request, this is the dealer's own request (see below)getOrigin()DamageOrigin. With no request, Divinity infers one: projectile →WEAPON_PROJECTILE, living attacker →WEAPON_MELEE, vanilla Thorns →EFFECT, otherwiseENVIRONMENT.isDescribed()says whether the origin came from a request or was inferredgetWeaponStatsMode()ADD, Fabled's legacy ignore-divinity mark meansIGNORE, and aDIVINITY_<type>hit meansREPLACE(orIGNORE, see below).RAWnever appears, because Divinity fires nothing for aRAWhitgetRequestedAmounts()DIVINITY_fire,default, ...). Empty when there are noneDivinityHitEvent.Prepare: the inputs, before the formula. You can change the damage per type and the defense per type (get/setDamageandget/setDefense, keyed byDamageAttribute/DefenseAttributeor by id). These are the same mapsStartreceives.DivinityHitEvent.Result: Divinity's final numbers after defenses, before anything is written to the Bukkit event. It gives:getDamage(type),getDamages()andgetDamagesById(), plusgetDefended(type)andgetIncomingDamages(), which are the inputs the formula sawisCritical()andisBlocked()setDamage(type, amount)andsetTotalDamage(total).setTotalDamagescales every type proportionally. If every type is at 0, the whole total goes on the default damage type.Whatever the listeners leave in place is what Divinity then uses: the fully-mitigated check, the
BASEit writes (rounded to 0.01 as today), the post-hit effects (vampirism, bleed, thornmail, AoE),Exit, and the combat log (DamageMeta).Firing order
Preparefires for every hit Divinity manages. It does not fire for:RAWrequests, vanilla-only damage handling, Fabled's throwaway events, non-living victims, hits refused byHooks.canFightsor the disabled sweep, and hits whoseBeforeScalewas cancelled.Resultfires if nothing cancelledPrepare,StartorPreand the hit was not dodged. This includesIGNOREhits, whichExitskips.Threading
Both events are synchronous. They fire on the server thread, inside the
EntityDamageEventhandler, like the old events.Cancellation
Prepareis the same as cancellingStart: the Bukkit event is cancelled and no further Divinity event fires.Resultcancels the hit after the calculation. The Bukkit event is cancelled, nothing is written toBASE, and the post effects andExitdo not run. The damage type's hit actions have already run by then, as they do today beforePre/Exitlisteners can react.setCancelled(x)also sets the Bukkit event's cancelled flag tox.How the old events map onto the new ones
All five old events keep firing at the same points with the same objects. They are marked
@Deprecatedwith a pointer to the new API, and Divinity's own listeners (durability, the stats refresh and the calculation itself) stay on them, so their behaviour does not change.BeforeScalePreparePrepareruns after Codex scaling. Nothing replaces "before scaling"StartPrepareStartlisteners still run afterPrepareand can override itPreResultto cancel after crit/block are known;Prepareto change inputsDodgeExitResultfor the final numbers; MONITOR on the Bukkit event for "after the hit landed"ExitskipsIGNOREhits;Resultdoes notDIVINITY_<type>inside an outer requestI checked this in the code.
DamageManager.dealDamagealways opens its own scope with aREPLACE/EXTERNALrequest. Codex'sDamageContexts.claimtakes the newest unclaimed scope for the target, which is that inner one. The dealer's outer request (for example Fabled'sIGNOREorRAWfrom the editor) is never claimed, so its mode and origin are lost. A new test pins the current behaviour first, then the fix.Codex has no public way to read an open request without claiming it, so the fix lives in Divinity and needs no Codex change. When
DamageContexts.isAnnounced(target)is true,dealDamagedoes not open an inner scope. Instead it records the typed amount locally for the duration of thedamage()call. This uses the same claim-once-per-event rule as Codex. The listener then claims the dealer's own request and combines it with the typed amount:RAWIGNOREExit. Defenses, dodge, crit and block still apply. This is what Fabled's legacy ignore-divinity mark already produces with aDIVINITY_<type>classifierADD,REPLACEREPLACE), as todayEither way the claimed request, and so the origin, is the dealer's (for example
SKILL, notEXTERNAL), and Fabled's outer scope reportsisClaimed() == true. With no outer request,dealDamagekeeps its current path unchanged.Not in this PR
Result, and Fabled can tell aRAWhit apart itself, so I left this out. If 4.3b needs it, it is a small addition.What changed
api/event/DivinityHitEvent.java(new):PrepareandResult, as designed above.api/event/DivinityDamageEvent.java: the class and all five subclasses are@Deprecated, each with its closest replacement. Their behaviour is unchanged.VanillaWrapperListener: claims aTypedDeals.Dealnext to the request, records origin, handled mode and requested amounts on theDamageMeta(describe), and firesPreparebeforeStart.DamageManager: firesResultafter the per-type loop.dealDamageuses aTypedDeals.Dealinstead of its own request when a request is already open on the target.TypedDeals(new): the typed amount of such a hit, claimed once per event by the same rule as Codex'sDamageContexts.DamageMeta:origin,weaponStatsMode,requestedAmounts.ItemDurabilityListenerandEntityManagerstay onExit, with@SuppressWarnings("deprecation"). The durability listener has a comment saying why.What the
DIVINITY_<type>fix changes on a live serverThis only affects a
DIVINITY_<type>hit dealt throughDamageRegistry.dealDamagewhile a dealer's request is open on the target. With no outer request,dealDamagetakes exactly its old path.RAWrequest is now honoured: the hit is not touched. It used to be calculated asREPLACE.IGNORErequest now makes the hit exempt: no on-hit effects, no attack power, noExit, so no durability cost. It used to be a fullREPLACEhit with on-hit effects.DamageMeta.getRequest()and the new events report the dealer's origin (for exampleSKILL) instead ofEXTERNAL.aSecondHitInsideTheSameRequest_isAnOrdinarySwingshows this: before the fix, a plain sword swing inside anIGNOREscope did 6 (the event's damage, asIGNORE) instead of the sword's 20.Characterization tests
None touched.
CombatCharacterizationTesthas no diff and every expectation in it still passes. New tests:TypedDamageInsideRequestTest(8 tests): theDIVINITY_<type>fix. I ran it against the unfixeddealDamagefirst; 4 tests failed (outerIgnore,outerRaw,outerAdd(request not claimed),aSecondHitInsideTheSameRequest). All 8 pass with the fix.DivinityHitEventTest(19 tests): firing order relative to the old events, noResulton dodge, nothing onRAW, origin and mode reporting (undescribed swing, environment, described request, legacy ignore-divinity), and changing or cancelling each event.CombatTestBase: shared setup for the two new classes.CombatCharacterizationTestkeeps its own copy on purpose, so it stays untouched.As a break-the-code check, I removed
if (result.isCancelled()) return;andresult_cancelled_writesNothingAndSkipsPostEffectsfailed.Build and test
mvn test, exit code 0: 316 run, 0 failures, 0 errors, 2 skipped. The 2 skipped are the existing trident tests inVanillaWrapperListenerTest, which need item cooldowns MockBukkit does not implement. The baseline ondevwas 289 run with the same 2 skipped.No Codex change is needed.
DamageContexts.isAnnouncedis already in the Codex this compiles against (1.3.0-SNAPSHOT), socodex.versionandMIN_CORE_VERSIONare unchanged.Not verified: Fabled's real call path for a
DIVINITY_<type>skill. Fabled is outside this session's GitHub scope, and the published Fabled snapshots predate fabled#1919. The fix assumes what the task describes: Fabled's scope is open on the target while it callsDamageRegistry.dealDamage. If Fabled instead calls it outside its scope, nothing changes from today. This is noted in the notes doc for 4.3b to check.Label
build:minor.release.ymlbumps by the highestbuild:*label among the PRs merged since the last release (1.1.1). Earlierbuild:majorPRs already make the next release 2.0.0, so any label keeps this PR in 2.0.0; none of them leads to 3.0.0.minordescribes the change itself: additive API plus deprecations.Docs
COMBAT_RESTRUCTURE_PLAN.md: 4.3 is split into 4.3a (this PR, done) and 4.3b (Fabled). The compatibility contract notes the deprecation. Phase 5 now says not to removeDodgebefore a replacement exists, and that theExitlisteners need a decision first.COMBAT_RESTRUCTURE_NOTES.md: the status table, and a new section "The new event surface (4.3a)" covering where the events fire, theIEventshared-handler-list trap, the newDamageMetafields,TypedDeals, and the Fabled call path that was not checked.🤖 Generated with Claude Code
https://claude.ai/code/session_01FaEyTuWrM4QJyDXghv2vfE